//
//  WBVisitorTableViewController.swift
//  weibobo
//
//  Created by KIMI on 16/9/20.
//  Copyright © 2016年 KIMI. All rights reserved.
//

import UIKit

class WBVisitorTableViewController: UITableViewController,WBVisitorViewDelegate {

    //是否登陆标识
    var isLogin: Bool = false
    
    //定义全局访客视图
    var visitorView: WBVisitorView?
    
    override func viewDidLoad() {
        super.viewDidLoad()

       
    }
    //自定义视图  重写loadView
   override func loadView() {
        
        if isLogin{
            super.loadView()
        }else{
            
            visitorView = WBVisitorView()
            //设置visitorview的代理
            visitorView?.delegate = self
            view = visitorView
   
            visitorView?.loginClosure = { [weak self] in
                
                self?.requestLoginOperation()
            }
            
            //未登录状态下 添加两个导航按钮
            setupUI()
    }
    }
    
    func setupUI() {
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: #selector(loginAction))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: #selector(loginAction))
    }
    
    func loginAction() {
        
        print("登录中")
    }
    
    //实现代理方法
    func didSelectedLogin() {
        
        print("delegate")
    }
    
    //请求登陆操作
    private func requestLoginOperation() {
        
        let OAuthVc = WBOAuthController()
        //包一个导航控制器
        let nav = WBNavigationController(rootViewController: OAuthVc)
        
        //model到新控制器
        present(nav, animated: true, completion: nil)
    }

    
}
